package com.guchenbo.example.socket.nio;

import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;

/**
 * @Author guchenbo
 * @Date 2018/10/24.
 */
public class BufferDemo {
    public static void main(String[] args) throws Exception {
        BufferDemo demo = new BufferDemo();
//        demo.test1();

        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        ServerSocket serverSocket = serverSocketChannel.socket();
//        serverSocket.bind();

        ServerSocketChannel serverSocketChannel1 = serverSocketChannel.bind(new InetSocketAddress(8888));

        System.out.println(serverSocketChannel1);
        System.out.println(serverSocketChannel);
    }

    private void test1() {
        ByteBuffer buffer = ByteBuffer.allocate(32);

        for (int i = 0; i < 10; i++) {
            buffer.put((byte) i);
        }
        buffer.flip();

        for (int i = 0; i < 5; i++) {
            System.out.println(buffer.get());
        }
        System.out.println(buffer.remaining());
        buffer.flip();

        for (int i = 0; i < 6; i++) {
            buffer.put((byte) (i + 1));
        }
    }
}
